import { RetCodeDefine } from "../config/RetCodeDefine";
import { ProtoUtils } from "../engine/socketserver/protocol/ProtoUtils";
import { ProtoConfig } from "../engine/socketserver/protocol/ProtoConfig";


export class RetCodeModel {

    public retCode: number = 0;
    public message: string = null;

    public static deserializeToModel(protoPack: any) {
        let model: RetCodeModel = new RetCodeModel();
        model.retCode = protoPack.getRetcode();
        model.message = protoPack.getMessage();
        return model;
    }

    public static createRetCodeModel(retCode: number=RetCodeDefine.OK, message: string = null) {
        let model: RetCodeModel = new RetCodeModel();
        model.retCode = retCode;
        if(message == null){
            message = RetCodeDefine.code2Msg.get(retCode);
        }
        model.message = message;
        return model;
    }

    public static serializeBinary(model:RetCodeModel){
        let protoPack = ProtoUtils.Create(ProtoConfig.resp_error_code);
        protoPack.setRetcode(model.retCode);
        protoPack.setMessage(model.message);
        return protoPack
    }

}